from flask import Flask
from flask_restful import Resource, Api
from flask_sqlalchemy import SQLAlchemy
from flask_restful import reqparse, abort, Api, Resource, fields,\
    marshal_with
from flask_restful_swagger import swagger
from .API.V1.resource.Information import Informationlist 
from .API.V1.action.User_operate import Login,Register
from .API.V1.action.Comment_opertate import getCommentlist,commenting,getCommentListByUserId
from .API.V1.action.Information_operate import getInformationlistByPostcodes,getInformationlistByUserId
from .API.V1.action.Information_operate import createInformation,unSupporting,supporting
from .API.V1.action.Information_operate import reporting
from .AdminBean import setAdmin




app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:Wwwwccctv1@121.36.9.1:3306/MapDB'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
api = Api(app)



db = SQLAlchemy(app)



setAdmin(app,db)


 
api = swagger.docs(Api(app), apiVersion='0.1',
                   basePath='http://localhost:8000',
                   resourcePath='/',
                   produces=["application/json", "text/html"],
                   api_spec_url='/api/spec',
                   description='地图资讯api')
'''
登录接口
'''
api.add_resource(Login,'/login',resource_class_kwargs={"db": db})


'''
注册接口
'''
api.add_resource(Register,'/register',resource_class_kwargs={"db": db})

'''
通过编码获取资讯列表接口
'''

api.add_resource(getInformationlistByPostcodes,'/getinformationlistbypost/<int:postcodes>,<string:token>',resource_class_kwargs={"db": db})

'''
通过创建人获取资讯列表接口
'''

api.add_resource(getInformationlistByUserId,'/getinformationlistbyuser/<int:create_user_id>,<string:token>',resource_class_kwargs={"db": db})



'''
创建资讯接口
'''
api.add_resource(createInformation,'/create_information',resource_class_kwargs={"db": db})

'''
获取评论接口
'''
api.add_resource(getCommentlist,'/information_comment/<int:information_id>,<string:token>',resource_class_kwargs={"db": db})



api.add_resource(getCommentListByUserId,'/information_comment_by_user_id/<int:user_id>,<string:token>',resource_class_kwargs={"db": db})
'''
创建评论接口
'''
api.add_resource(commenting,'/create_coment',resource_class_kwargs={"db": db})



'''
点赞接口
'''
api.add_resource(supporting,'/create_support',resource_class_kwargs={"db": db})



'''
踩接口
'''
api.add_resource(unSupporting,'/create_un_support',resource_class_kwargs={"db": db})


'''
举报接口
'''
api.add_resource(reporting,'/create_reporting',resource_class_kwargs={"db": db})





























# '''
# 资讯表


# title = 标题
# content = 内容
# picture = 图片url
# create_user_id = 创建人
# support = 获赞数
# unsupported = 获踩数
# postcodes = 邮政编码 北京 = 100010
# place = 地点
# coordinate_x = x坐标
# coordinate_y = y坐标
# state = 状态  1为上线  0 为下线
# '''

api.add_resource(Informationlist,'/information',resource_class_kwargs={"db": db})
# api.add_resource(Information,'/information/<article_id>',resource_class_kwargs={"db": db})

# ''' 
# 管理员表l
# acoount = 账户
# password = 密码
# isadmin = 权限等级
# '''


# api.add_resource(Adminlist,'/admin',resource_class_kwargs={"db": db})
# api.add_resource(Admin, '/admin/<admin_id>', resource_class_kwargs={"db": db})

# '''
# 用户表
# name = 用户名
# head_picture = 头像url
# phone = 手机号
# examine =审核员
# password = 密码
# support = 点赞数
# '''

# api.add_resource(Userlist,'/user',resource_class_kwargs={"db": db})
# api.add_resource(User, '/user/<user_id>', resource_class_kwargs={"db": db})

# '''
# 点赞表
# surpport_user_id = 点赞者id
# information_id = 资讯id
# create_user_id = 资讯发布者id
# '''


# api.add_resource(Supportlist,'/supportlist',resource_class_kwargs={"db": db})
# api.add_resource(Support, '/support/<support_id>', resource_class_kwargs={"db": db})

# '''
# 举报表
# content = 内容
# informaiton_id = 资讯id
# report_user_id = 举报者id
# create_user_id = 资讯发布者id
# '''

# api.add_resource(Reportlist,'/report',resource_class_kwargs={"db": db})
# api.add_resource(Report, '/report/<report_id>', resource_class_kwargs={"db": db})


# '''
# 评论表
# content = 内容
# information_id = 资讯id
# comment_user_id = 评论的用户id
# create_user_id = 资讯发布者id
# '''


# api.add_resource(Commentlist,'/comment',resource_class_kwargs={"db": db})
# api.add_resource(Comment,'/comment/<comment_id>', resource_class_kwargs={"db": db})

